package edu.sctu.zhu.dao;

import edu.sctu.zhu.bean.Users;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zhu on 2015/11/29.
 */
@Repository
@Transactional
public interface UsersDao extends CrudRepository<Users,Long>{
    @Query(value = " select users.id from users where users.username=? ",nativeQuery = true)
    public Long findIdByUsername(String username);

    @Query(value = " select * from users where users.username=? ",nativeQuery = true)
    public Users findByUsername(String username);

    @Query(value = "SELECT * FROM users WHERE is_pass = FALSE",nativeQuery = true)
    public List<Users> findNotPass();


    @Modifying(clearAutomatically = true)
    @Query(value = " update users SET is_pass=TRUE,enabled=TRUE WHERE id=?"  , nativeQuery = true)
    public void setPass(Long id);
}
